package main

import (
	"chainproxy/config"
	"chainproxy/db"
	"chainproxy/log"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"github.com/tidwall/gjson"
)

//const upstream = "https://goproxy.io"
//const upstream = "http://goproxy.cn"
var ProxyResult chan gjson.Result

func main() {
	ProxyResult = make(chan gjson.Result, 1000)
	log.InitLog()
	f := config.GetBool("db.enable")
	if f{
		db.InitDb()
	}
	go DynamicChooseUpstream(ProxyResult)
	go TimingTask()

	port := config.GetString("server.port")
	log.Logger.Info("-------Start Proxy--------")
	log.Logger.Info("Run in ", port)

	l, _ := logrus.ParseLevel(config.GetString("log.level"))
	gin.DefaultWriter = log.Logger.WriterLevel(l)
	r := gin.Default()
	r.GET("/chain/*pathname", moduleListHandler)
	_ = r.Run(port)
}
